#!/bin/sh

set -e
set -x
[ $# -ne 1 ] && exit 1
ip=$((2+$1))
ip="172.172.0.${ip}"
port=$((5000+$1))
cfg="/home/zookeeper/zoo${1}.cfg"
data="/home/zookeeper/dataDir${1}"
name="zp${1}"
docker run --rm -itd -v ${cfg}:/opt/zookeeper-3.4.13/conf/zoo.cfg \
                    -v ${data}:${data} --network=zp --ip ${ip} \
                    -p ${port}:2181 --name ${name} zookeeper \
                    bash -c "/opt/zookeeper-3.4.13/bin/zkServer.sh start && bash"
